package com.shop.controller;

import com.shop.service.GoodsService;
import com.shop.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:zyn
 * @Date:2025/9/19--13:55:38
 */
@WebServlet("/getGoods.do")
public class GoodsServlet extends HttpServlet {
    private GoodsService gs=new GoodsServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       int pageNum;
       int pageSize;
       try {
           pageNum=Integer.parseInt(req.getParameter("pageNum"));
       }catch(Exception e){
           pageNum=1;
       }
        try {
            pageSize=Integer.parseInt(req.getParameter("pageSize"));
        }catch(Exception e){
            pageSize=5;
        }
        req.setAttribute("goodsPage",gs.getAllGoods(pageNum,pageSize));
        req.getRequestDispatcher("goods.jsp").forward(req,resp);
    }
}
